package vn.edu.saigontech.ncms.web.teacher;

import vn.edu.saigontech.ncms.util.Checker;
import vn.edu.saigontech.ncms.util.DateUtil;
import vn.edu.saigontech.ncms.web.AbstractValidator;

@SuppressWarnings("serial")
public class ValidateTeachingHourReportAction extends AbstractValidator {

	private String fromDate;
	private String toDate;

	@Override
	public String check() {
		if(Checker.isEmpty(this.fromDate)) {
			this.sendKeyError("validator.required", "fromDate");
		}
		if(!Checker.isDate(this.fromDate, this.i18n("format.date"))) {
			this.sendKeyError("validator.mask", "fromDate", "format.date");
		}
		if(Checker.isEmpty(this.toDate)) {
			this.sendKeyError("validator.required", "toDate");
		}
		if(!Checker.isDate(this.toDate, this.i18n("format.date"))) {
			this.sendKeyError("validator.mask", "toDate", "format.date");
		}
		if(DateUtil.fromString(this.fromDate, this.i18n("format.date")).after(DateUtil.fromString(this.toDate, this.i18n("format.date")))) {
			this.sendKeyError("validator.greater", "toDate", "fromDate");
		}
		return this.toSuccess();
	}

	public String getFromDate() {
		return fromDate;
	}

	public void setFromDate(String fromDate) {
		this.fromDate = fromDate;
	}

	public String getToDate() {
		return toDate;
	}

	public void setToDate(String toDate) {
		this.toDate = toDate;
	}

}
